<template>
  <div>
    <transition name="move">
      <span @click.prevent="subFoodsNum(food)" v-if="food.count">-</span>
    </transition>
    <transition name="move">
      <input
        type="text"
        class="addShopNum"
        v-model="food.count"
        v-if="food.count"
      />
    </transition>
    <transition name="move">
      <span @click.prevent="addFoodsNum(food)">+</span>
    </transition>
  </div>
</template>

<script>
export default {
  props: ['food'],
  methods: {
    // 添加购物车数量
    addFoodsNum(food) {
      this.$store.dispatch('addFoodsNum', food)
    },
    // 减少
    subFoodsNum(food) {
      this.$store.dispatch('subFoodsNum', food)
    }
  }
}
</script>

<style lang="less" scoped>
.addShopNum {
  border: 0.026667rem solid #ccc;
  width: 1.333333rem;
  margin: 0 0.08rem;
  height: 0.7rem;
  font-size: 0.433333rem;
  text-align: center;
}
span {
  display: inline-block;
  height: 0.7rem;
  width: 0.7rem;
  background-color: #999;
  color: white;
  border-radius: 50%;
  text-align: center;
  line-height: 0.7rem;
  font-size: 0.78rem;
  vertical-align: middle;
}
// 动画
.move-enter-active,
.move-leave-active {
  transition: all 0.3s;
}
.move-enter,
.move-leave-to {
  opacity: 0;
  transform: translateX(18px) rotate(180deg);
}
</style>
